package com.amox.uitest.adapter;

import org.dom4j.Element;
import org.dom4j.Node;

import com.amox.uitest.common.KeyWord;
import com.amox.uitest.kit.LogKit;
import com.amox.uitest.kit.StrKit;
import com.amox.uitest.kit.XMLKit;
import com.amox.uitest.tcase.BaseTestCase;

public class CallAdapter extends BaseAdapter<Boolean> {
	
	private FuncAdapter funcAdapter;
	
	public CallAdapter(BaseTestCase uitest) {
		super(uitest);
		funcAdapter = new FuncAdapter(uitest);
	}
	
	@Override
	public Boolean adapter(Element element) throws Exception {
		return call(element);
	}
	
	private boolean call(Element element) throws Exception {
		String value = StrKit.me().toSingleLine(element.getStringValue());
		if(value.charAt(0) != '#') {
			LogKit.printLog("The Call Method[0] Should Be Start With [1]", value, "#");
			return false;
		}
		Node classNode = XMLKit.me(uitest).closet(element, KeyWord.clazz.toString());
		Node func = XMLKit.me(uitest).byAttr(classNode, KeyWord.func, KeyWord.id, value.substring(1).trim());
		if(!funcAdapter.adapter((Element)func)) {
			return false;
		}
		
		return true;
	}
}
